#初始化文件,成为一个包

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from config import mapConfig

#创建sqlalchemy对象
db = SQLAlchemy()

def create_app(config_name):
    #创建实例
    app = Flask(__name__)
    #根据类来加载配置信息
    app.config.from_object(mapConfig.get(config_name))
    #初始化sqlalchemy对象
    db.init_app(app)

    #获取蓝图对象
    from flask_shop.user import user_bp
    app.register_blueprint(user_bp)

    #获取菜单蓝图对象
    from flask_shop.menu import menu_bp
    app.register_blueprint(menu_bp)

    #获取角色蓝图对象
    from flask_shop.role import role_bp
    app.register_blueprint(role_bp)

    #获取善品蓝图对象
    from flask_shop.category import category_bp
    app.register_blueprint(category_bp)
    
    #获取商品属性蓝图
    from flask_shop.category import attr_bp
    app.register_blueprint(attr_bp)

    #获取商品蓝图
    from flask_shop.product import product_bp
    app.register_blueprint(product_bp)

    #获取上传图片蓝图
    from flask_shop.product import img_bp
    app.register_blueprint(img_bp)

    #获取订单蓝图
    from flask_shop.order import order_bp
    app.register_blueprint(order_bp)
    #返回app实例
    return app

